package cn.edu.scau.cmi.huangzhiyuan.db.client;

import java.util.List;

import cn.edu.scau.cmi.huangzhiyuan.db.domain.Person;
import cn.edu.scau.cmi.huangzhiyuan.db.domain.Student;
import javafx.collections.ObservableList;
import javafx.scene.control.ChoiceBox;
import javafx.scene.layout.StackPane;

public class BodyPane extends StackPane {
	
	public ChoiceBox<Person> names;
	
	public BodyPane() {
		setChoiceBox();
		setStyle();
	}
	
	private void setChoiceBox() {
		names = new ChoiceBox<>();
		getChildren().add(names);
	}
	
	private void setStyle() {
		names.setPrefWidth(400);
	}
	

	public void setPerson(List<Person> persons) {
		int selectIndex = names.getSelectionModel().getSelectedIndex();
		
		ObservableList<Person> items = names.getItems();
		items.clear();
		for(int i=0; i<persons.size(); i++) {
			items.add(persons.get(i));
		}
		
		names.getSelectionModel().select(selectIndex);
	}
}
